/*
 * Folder.java
 *
 * This file is part of Netuno Psamata.
 *
 * CajuScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3, or (at your option)
 * any later version.
 *
 * CajuScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CajuScript.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.netuno.psamata.io;

/**
 * Folder.
 * @author eduveks
 */
public class Folder {    
    /**
     * Delete folder.
     * @param path Folder path
     */
    public static boolean delete(String path) {
        return delete(new java.io.File(path));
    }

    /**
     * Delete folder.
     * @param folder Folder
     */
    public static boolean delete(java.io.File dir) {
        if (dir.isDirectory()) {
            for (java.io.File f : dir.listFiles()) {
                delete(f);
            }
        }
        return dir.delete();
    }
    /**
     * Delete folder.
     * @param path Folder path
     */
    public static void deleteOnExit(String path) {
        deleteOnExit(new java.io.File(path));
    }

    /**
     * Delete folder.
     * @param folder Folder
     */
    public static void deleteOnExit(java.io.File dir) {
        if (dir.isDirectory()) {
            for (java.io.File f : dir.listFiles()) {
                deleteOnExit(f);
            }
        }
        dir.deleteOnExit();
    }
    
    /**
     * Folder size.
     * @param path Folder path
     */
    public static long size(String path) {
        return size(new java.io.File(path));
    }
    
    /**
     * Folder size.
     * @param folder Folder
     */
    public static long size(java.io.File dir) {
    	if (dir.isDirectory()) {
    		int size = 0;
            for (java.io.File f : dir.listFiles()) {
            	size += size(f);
            }
            return size;
        }
        return dir.length();
    }
}
